package api;

import model.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.*;

@WebServlet("/api/romve.json")
public class romve extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String cid = req.getParameter("cid");
        delete(cid);
        resp.sendRedirect("/CompanyPost.html");
    }
    public static void delete(String cid){
        try {
            try(Connection c = DBUtil.getConnection()){
                String sql = "DELETE from company WHERE cid = ?";
                try (PreparedStatement s = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
                    s.setString(1,cid);
                    s.executeUpdate();
                }
            }
        } catch (SQLException exception) {
            exception.printStackTrace();
        }
    }
}
